package com.lzw.controller.dormitoryAdmin;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzw.anno.Log;
import com.lzw.pojo.Feedback;
import com.lzw.service.dormitoryAdmin.FeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/feedback")
@CrossOrigin(origins = "http://localhost:7070")
public class FeedbackController {

    @Autowired
    private FeedbackService feedbackService;

    //分页查询
    @GetMapping("/list")
    public PageInfo<Feedback> list(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate feedbackDate,
            Integer studentId){
        PageHelper.startPage(pageNum,pageSize);
        List<Feedback> list = feedbackService.list(pageNum,pageSize,feedbackDate,studentId);
        return new PageInfo<>(list);
    }


    //回复反馈记录
    @Log
    @PutMapping("/update")
    public String update(@RequestBody Feedback feedback){
        feedbackService.update(feedback);
        return "回复成功";
    }

    //删除
    @Log
    @DeleteMapping("/delete/{ids}")
    public String delete(@PathVariable List<Integer> ids){
        feedbackService.delete(ids);
        return "删除成功";
    }
}
